﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyWeb.ServiceBus.Common
{
    public class MyHttpClient
    {
        /// <summary>
        /// 发送get请求
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public async Task<string> GetAsync(string url)
        {
            var Response = await new HttpClient().GetAsync(url);
            Response.EnsureSuccessStatusCode();
            //var RETURN_CODE = Response.Headers.ToList().Where(p => p.Key == "RETURN_CODE").FirstOrDefault().Value.FirstOrDefault();
            var datadto = Response.Content.ReadAsStringAsync();
            var result = datadto.Result;

            return result;
        }

        public async Task<string> PostAsync(string url, HttpContent content)
        {
            HttpClient httpClient = new HttpClient();
            httpClient.Timeout = TimeSpan.FromSeconds(6000);

            //httpClient.DefaultRequestHeaders.Add("","");

            var Response = await httpClient.PostAsync(url,content);
            Response.EnsureSuccessStatusCode();
            //var RETURN_CODE = Response.Headers.ToList().Where(p => p.Key == "RETURN_CODE").FirstOrDefault().Value.FirstOrDefault();
            var datadto = Response.Content.ReadAsStringAsync();
            var result = datadto.Result;

            return result;
        }

    }
}
